// var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
var userCategory=JSON.parse(sessionStorage.getItem("userCategory"));
var userActive=JSON.parse(sessionStorage.getItem("userActive"));
var sroleft=JSON.parse(sessionStorage.getItem("sroleft"));
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
$(".seeInfo-navleft").scrollLeft(sroleft);
//console.log(userCategory)
Vue.component('seeHeader',{
    // nameL:"seeHeader",
    props:["uid","number"],
    template: '<div class=""><header class="seeIndex-header navFixed">\n' +
    '        <a class="seeIndex-logo"></a>\n' +
    '        <a class="seeIndex-time"></a>\n' +
    '        <a class="seeIndex-sear">搜索你感兴趣的视频</a>\n' +
    '        <a class="seeIndex-play" @click="getMoreDiv()"></a>\n' +
    '    </header>\n' +
    '    <nav class="seeInfo-nav clearfix">' +
    '       <div class="seeInfo-navleft">\n' +
        '        <a href="/" :class="{active:categoryId==0}" @click="getNext(0,0)">推荐</a>\n' +
        '        <a href="/see/enterpriseAd" @click="getNext(2,0)" :class="{active:categoryId==2}">企业</a>\n' +
        // '        <a href="/see/cityAd" @click="getNext(3,0)" :class="{active:categoryId==3}">城市</a>\n' +
        '        <a :class="{active:categoryId==item.categoryId}" v-for="(item,index) in userCategoryList" @click="getNext(item.categoryId,item.type)">{{item.name}}</a>' +
    '        </div>\n' +
    // '        <a :class="{active:number==5}">传统文化</a></div>\n' +
    '        <span class="seeIndex-zzhed"></span>\n' +
    '        <a class="seeIndex-zmore" href="/see/channelNav">导航</a>\n' +
    '    </nav><div class="nav-moreDiv" v-if="isMoreDiv">\n'+
    '            <strong></strong>\n' +
/*    '            <a class="seeIndex-nav1">发布视频</a>\n' +*/
    '            <a class="seeIndex-nav2">每日任务<span></span></a>\n' +
    '            <a class="seeIndex-nav3">今日收益</a>\n' +
    '        </div>\n' +
    '</div>',
    data: function () {
        return {
            id:this.uid,
            num:this.number,
            categoryId:userActive,
            sroleft:sroleft,
            isMoreDiv:false,
            userCategoryList:{}//分类信息
        }
    },
    watch:{
        id:function(){
            this.getUserCategoryList(1,this.id)
        }
    },
    mounted:function(){
        this.getUserCategoryList(2);
        if(this.num==0){
            this.categoryId=this.num;
            sessionStorage.setItem("userActive",JSON.stringify(this.num));
        }
        console.log(this.sroleft)
        // var ss=$(".seeInfo-navleft").scrollLeft();

    },
    methods:{
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        //通过当前登录用户id 获取分类信息
        getUserCategoryList:function(type,id){
            var that=this;
            that.id=id;
            if(type!=1&&userCategory){
                //console.log(userCategory)
                that.userCategoryList=userCategory;
            }else{
                var data={
                    loginUid:id||userInfo.id,
                    isFirst:2
                };
                this.ajax({url:"/selfMedia/getUserCategoryList",data:data,dataType:"json",method:"post"},function(b){
                    if(b.json.code==0&&b.json.data){
                        that.userCategoryList=b.json.data;
                        sessionStorage.setItem("userCategory",JSON.stringify(that.userCategoryList));
                        console.log(that.userCategoryList)
                    }else{
                        vm.$refs.prompt.toast("获取分类失败！");
                    }
                });
            }

        },
        //点击跳转
        getNext:function(categoryId,type){
            console.log(categoryId+"---------"+type)
            // this.categoryId=id;
            // var tabs = this.$el.querySelectorAll('.seeInfo-navleft a');
            // for (var i = 0; i < tabs.length; i++) {
            //     tabs[i].removeAttribute('class');
            // }
            // tabs[index+1].setAttribute('class', 'active');
            var sroleft=$(".seeInfo-navleft").scrollLeft();
            sessionStorage.setItem("userActive",JSON.stringify(categoryId));
            sessionStorage.setItem("sroleft",JSON.stringify(sroleft));
            if(type==1){
                if(categoryId=="4fa65bb1646948eebfb65e98b2feac84"){
                    location.href="/see/recruitPage?categoryId="+categoryId;
                }else{
                    location.href="/see/selfMediaPage?categoryId="+categoryId;
                }
            }else if(type==3){
                location.href="/see/cityAd";
            }

        },
        //显示隐藏
        getMoreDiv:function(){
            // this.isMoreDiv=!this.isMoreDiv;
        }
    }
});